﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace regExport
{
    class Class1
    {
        //From the main method this is where ExportReg is being called from.
        //This method will grab the reg key,the Destination path, and the Source server. 
        static public void ExportReg(string RegKey, string SavePath, string SourceServerName)
        {
            string path = "\"" + SavePath + "\"";
            string key = "\"" + RegKey + "\"";

            var proc = new Process();
            try
            {
                proc.StartInfo.FileName = "regedit.exe";
                proc.StartInfo.UseShellExecute = false;
                proc = Process.Start("regedit.exe", "/e " + path + " " + key + "");

                if (proc != null) proc.WaitForExit();
            }
            finally
            {
                if (proc != null) proc.Dispose();
            }

        }

        //From the main method this is where ImportReg is being called from.
        //This method will grab the reg key,the Destination path, and the Destination server. 
        static public void ImportReg(string RegKey2, string SavePath2, string ServerName)
        {
            string path = "\"" + SavePath2 + "\"";
            string key = "\"" + RegKey2 + "\"";

            var proc = new Process();
            try
            {
                proc.StartInfo.FileName = "regedit.exe";
                proc.StartInfo.UseShellExecute = false;
                proc = Process.Start("regedit.exe", "/s " + path + " " + key + "");

                if (proc != null) proc.WaitForExit();
            }
            finally
            {
                if (proc != null) proc.Dispose();
            }
        }

    }
}
